home *** CD-ROM | disk | FTP | other *** search
/ The AGA Experience 3 / AGA Experience Volume 3 (1997)(NFA - SAdENESS)[!].iso / rexx / links.rexx < prev    next >
OS/2 REXX Batch file  |  1995-09-21  |  10KB  |  359 lines

  1. /****************************************************************************
  2.  *                                                                          *
  3.  * $VER: Links 1.16 (18 Jul 1995)
  4.  *                                                                          *
  5.  *                      Written by Freddy Ariës                             *
  6.  *                                                                          *
  7.  * ARexx script to find unrelated family trees in the database              *
  8.  * It will detect all family trees within the database that have no links   *
  9.  * (spouse, parent or child links) to other present family trees.           *
  10.  * Eg. useful to find out if you forgot to add a link somewhere...          *
  11.  *                                                                          *
  12.  * This script uses (by default) the rexxreqtools.library (which requires   *
  13.  * a version of reqtools larger than 2.0 and rexxsyslib.library)            *
  14.  * If you do not have these, change the line 'usereq = 1' to 'usereq = 0'   *
  15.  *                                                                          *
  16.  * Now with progress indicator, using rexxarplib.library (requested by      *
  17.  * Master Robbie himself :-) )                                              *
  18.  *                                                                          *
  19.  ****************************************************************************/
  20.  
  21. options results
  22. arg outname outval
  23.  
  24. versionstr = "1.16"
  25. usereq = 1; /* change this to 0 if you don't want to use reqtools */
  26. useirn = 1
  27. outp = 1; output = stdout
  28. plwidth = 78;  /* linewidth of the printer */
  29. fill = 9;      /* number of spaces at the beginning of lines */
  30. prgrs = 1; pgopen = 0; /* use RexxArp progress indicator */
  31.   /* change prgrs to 0 for not using it */
  32. NL = '0A'x
  33.  
  34. signal on IOERR
  35.  
  36. do while outname = '?'
  37.   writeln(stdout, "OUTFILE/A,QUIET/S,NOREQ/S ")
  38.   pull outname outval
  39. end
  40.  
  41. if outname ~= "" then do
  42.   if outname = "QUIET" | outname = "NOREQ" then do
  43.     outval = outname; outname = ""
  44.   end
  45. end
  46.  
  47. if outval = "QUIET" then do
  48.   outp = 0; usereq = 0; prgrs = 0
  49. end
  50. else if outval = "NOREQ" then do
  51.   usereq = 0; prgrs = 0
  52. end
  53.  
  54. if usereq & ~show('l','rexxreqtools.library') then do
  55.   if exists('libs:rexxreqtools.library') then
  56.     call addlib('rexxreqtools.library',0,-30,0)
  57.   else do
  58.     usereq = 0; outp = 1
  59.     Tell("Unable to open rexxreqtools.library - using text output")
  60.   end
  61. end
  62.  
  63. if ~usereq then prgrs = 0
  64.  
  65. /* These first few lines were stolen from Peter Billings - thanks Peter ;-) */
  66. if ~show('P','SCIONGEN') then do
  67.   TermError('I am sorry to say that the SCION Genealogist' || NL ||,
  68.     'database is not available. Please start the' || NL ||,
  69.     'SCION program BEFORE using this script!')
  70. end
  71.  
  72. if prgrs & ~show('l','rexxarplib.library') then do
  73.   if exists('libs:rexxarplib.library') then
  74.     call addlib('rexxarplib.library',0,-30,0)
  75.   else
  76.     prgrs = 0
  77. end
  78.  
  79. myport = "SCIONGEN"
  80. address value myport
  81. GETDBNAME
  82. dbname = upper(RESULT)
  83.  
  84. Arrays. = ""
  85. CurrIRN = 1; arr = 1; Arrays.1 = "1 "
  86. NumArrs = 1; Found = 1
  87.  
  88. if outp & ~usereq then do
  89.   Tell("Scion Links Finder v"||versionstr||" by Freddy Ariës")
  90.   Tell("Current Scion database: "||dbname)
  91.   Tell("Be patient - this may take a while...")
  92. end
  93.  
  94. /* It's a good habit to add the ".scion" extension to Scion database files */
  95. dblen = length(dbname)
  96. if dblen>6 & right(dbname, 6)=".SCION" then dbname=left(dbname, dblen - 6)
  97.  
  98. if outname = "" then do
  99.   if outp then do
  100.     if usereq then do
  101.       odev = rtezrequest('Current Scion database: '||dbname||,
  102.        NL||'Where should the Links output be sent to?'||,
  103.        NL,' _File |_Printer|_Screen|_Nowhere','Scion Links Finder v'||versionstr||' by Freddy Ariës','rt_pubscrname = SCIONGEN')
  104.       select
  105.         when odev = 1 then do
  106.           /* We need a file requester for further data */
  107.           outname = rtfilerequest(,dbname||'.LNK','Output filename',,'rtfi_buffer = true   rt_pubscrname = SCIONGEN   rtfi_initialpath = RAM:',)
  108.           if outname = '' then
  109.             outname = dbname||'.LNK'
  110.         end
  111.         when odev = 2 then
  112.           outname = 'PRT:'
  113.         when odev = 3 then
  114.           outname = 'STDOUT'
  115.         otherwise
  116.           EXIT
  117.           /* You selected 'Nowhere' */
  118.       end
  119.     end
  120.     else do
  121.       Tell("Enter output file (filename with complete path, or PRT: for printer,")
  122.       TellNN("or STDOUT for screen): ")
  123.       pull outname
  124.       Tell("Destination: "||outname)
  125.       TellNN("Continue (y/n)? ")
  126.       pull conf
  127.       /* Note that left works on empty strings ("") too! */
  128.       if left(conf,1) ~= "Y" then do
  129.         Tell("Goodbye...")
  130.         EXIT
  131.       end
  132.       Tell("")
  133.     end
  134.   end
  135.   else
  136.     outname = "RAM:"dbname".LNK"
  137.     /* If we're not allowed to use stdout, default to this filename */
  138. end
  139.  
  140. if prgrs then do
  141.   Postmsg(10, 10, "Scion Links Finder (by Freddy Ariës)\Database: "||dbname||"\ \ ", "SCIONGEN")
  142.   pgopen = 1
  143. end
  144.  
  145. GETTOTALIRN
  146. TotalIRN = RESULT
  147. if pgopen then Postmsg(,, "\\Processing person:\", "SCIONGEN")
  148.  
  149. do while CurrIRN <= TotalIRN
  150.   if pgopen then Postmsg(,,"\\\"||CurrIRN||" (of "||TotalIRN||")", "SCIONGEN")
  151.   if Found then do
  152.     MarrNum = 0; marrexist = 1
  153.  
  154.     do while marrexist
  155.       GETMARRIAGE CurrIRN MarrNum
  156.       marriage = RESULT
  157.       EXISTFAMILY marriage
  158.       if RESULT = 'YES' then do
  159.         marrexist = 1
  160.  
  161.     PrsnIRN = 0
  162.     GETPRINCIPAL marriage
  163.     ptnr = RESULT
  164.     EXISTPERSON ptnr
  165.     if RESULT = 'YES' then do
  166.       if ptnr ~= CurrIRN then PrsnIRN = ptnr
  167.     end
  168.     if PrsnIRN = 0 then do
  169.       GETSPOUSE marriage
  170.       ptnr = RESULT
  171.       EXISTPERSON ptnr
  172.       if RESULT = 'YES' then do
  173.         if ptnr ~= CurrIRN then PrsnIRN = ptnr
  174.       end
  175.     end
  176.  
  177.     EXISTPERSON PrsnIRN
  178.         if RESULT = 'YES' then
  179.           arr = HandlePerson(PrsnIRN)
  180.  
  181.     ChildNum = 0; childexist = 1
  182.     do while childexist
  183.       GETCHILD marriage ChildNum
  184.       child = RESULT
  185.       EXISTPERSON child
  186.       if RESULT = 'YES' then do
  187.             childexist = 1
  188.         arr = HandlePerson(child)
  189.         ChildNum = ChildNum + 1
  190.       end
  191.       else childexist = 0
  192.     end
  193.  
  194.         MarrNum = MarrNum + 1
  195.       end
  196.       else marrexist = 0
  197.     end
  198.  
  199.     GETPARENTS CurrIRN
  200.     ParFGRN = RESULT
  201.     EXISTFAMILY ParFGRN
  202.     if RESULT = 'YES' then do
  203.       GETPRINCIPAL ParFGRN
  204.       PrsnIRN = RESULT
  205.       EXISTPERSON PrsnIRN
  206.       if RESULT = 'YES' then do
  207.         arr = HandlePerson(PrsnIRN)
  208.       end
  209.  
  210.       GETSPOUSE ParFGRN
  211.       PrsnIRN = RESULT
  212.       EXISTPERSON PrsnIRN
  213.       if RESULT = 'YES' then
  214.         arr = HandlePerson(PrsnIRN)
  215.  
  216.       /* Note that we don't have to process siblings, because they will
  217.        * be processed with their parents, and because you cannot create
  218.        * a family group without at least one parent
  219.        */
  220.     end
  221.   end
  222.  
  223.   CurrIRN = CurrIRN + 1
  224.   EXISTPERSON CurrIRN
  225.  
  226.   if RESULT = 'YES' then do
  227.    arr = GetArray(CurrIRN)
  228.    Found = 1
  229.   end
  230.   else Found = 0
  231. end
  232.  
  233. if pgopen then Postmsg(,, "\\Writing output...\ ", "SCIONGEN")
  234.  
  235. if outname ~= "STDOUT" then do
  236.   output = 'OUTPUT'
  237.   if ~open(output, outname, "w") then
  238.     TermError("ERROR: Unable to open output file.")
  239. end
  240.  
  241. /* Now output the resulting arrays of IRNs! */
  242. do out = 1 for NumArrs
  243.   PrintLines("Group "||out||": "||Arrays.out, fill)
  244. end
  245.  
  246. if pgopen then do
  247.   Postmsg()
  248.   pgopen = 0
  249. end
  250.  
  251. if usereq then do
  252.   rtezrequest('Scion Links Finder is ready.' || NL ||'Persons parsed: '||,
  253.     TotalIRN,,'Links Message:','rt_pubscrname = SCIONGEN')
  254. end
  255. else
  256.   Tell("Done ("||TotalIRN||" persons parsed)."||NL)
  257.  
  258. EXIT
  259.  
  260.  
  261. GetArray: PROCEDURE EXPOSE Arrays. NumArrs
  262. parse arg prsn
  263. do CurrArr = 1 for NumArrs
  264.   col = find(Arrays.CurrArr, prsn)
  265.   if col > 0 then return CurrArr
  266. end
  267. /* Not already present, then give person a new array */
  268. NumArrs = NumArrs + 1
  269. Arrays.NumArrs = prsn||' '
  270. return NumArrs
  271.  
  272. MergeArrs: PROCEDURE EXPOSE Arrays. NumArrs
  273. parse arg arr1, arr2
  274. if arr1 <= arr2 then do
  275.   minarr = arr1; maxarr = arr2
  276. end
  277. else do
  278.   minarr = arr2; maxarr = arr1
  279. end
  280. Arrays.minarr = Arrays.minarr||Arrays.maxarr
  281. if maxarr ~= NumArrs then
  282.   Arrays.maxarr = Arrays.NumArrs
  283. Arrays.NumArrs = ""
  284. NumArrs = NumArrs - 1
  285. return minarr
  286.  
  287. HandlePerson: PROCEDURE EXPOSE Arrays. NumArrs arr
  288. parse arg prsn
  289. CurrArr = 1; pers = 0
  290. do until pers ~=  0 | CurrArr > NumArrs
  291.   if find(Arrays.CurrArr, prsn) > 0 then pers = CurrArr
  292.   CurrArr = CurrArr + 1
  293. end
  294. if pers = 0 then do
  295.   /* Person isn't already present; give him same array as CurrIRN person */
  296.   pers = arr
  297.   Arrays.arr = Arrays.arr||prsn||' '
  298. end
  299. if pers ~= arr then
  300.   arr = MergeArrs(pers, arr)
  301. return arr
  302.  
  303. PrintLines: PROCEDURE EXPOSE output plwidth
  304. parse arg ostr, fill
  305. do while ostr ~= ""
  306.   nnl = plwidth+1
  307.   if length(ostr) > plwidth then do
  308.     do until pc = ' ' | nnl = 1
  309.       pc = substr(ostr, nnl, 1)
  310.       nnl = nnl - 1
  311.     end
  312.     if nnl = 1 then do
  313.       prtstr = left(ostr, plwidth)
  314.       ostr = delstr(ostr, 1, nnl)
  315.     end
  316.     else do
  317.       prtstr = left(ostr, nnl)
  318.       ostr = delstr(ostr, 1, nnl+1)
  319.     end
  320.   end
  321.   else do
  322.     prtstr = ostr
  323.     ostr = ""
  324.   end
  325.   writeln(output, prtstr)
  326.   if ostr ~= "" then
  327.     ostr = copies(' ',fill)||ostr
  328. end
  329. return 0
  330.  
  331. Tell: PROCEDURE EXPOSE outp
  332. parse arg str
  333. if outp then writeln(stdout, str)
  334. return 0
  335.  
  336. TellNN: PROCEDURE EXPOSE outp
  337. parse arg str
  338. if outp then writech(stdout, str)
  339. return 0
  340.  
  341. TermError: PROCEDURE EXPOSE outp output usereq pgopen
  342. parse arg str
  343. if pgopen then Postmsg()
  344. /* If you turned off stdout, no error messages will be shown! */
  345. if usereq then
  346.   rtezrequest(str,'E_xit','Links Message:','rt_pubscrname = SCIONGEN')
  347. else do
  348.   Tell(str || '0A'x)
  349. end
  350. /* close(output) */
  351. EXIT
  352.  
  353. IOERR:
  354.   bline = SIGL
  355.   say "I/O error #"||RC||" detected in line "||bline||":"
  356.   say sourceline(bline)
  357.   if pgopen then Postmsg()
  358.   EXIT
  359.